package com.zhitong.money.services;

import com.zhitong.money.entity.MsgEmp;
import com.zhitong.money.exception.UpdateException;
import com.zhitong.money.mapper.MsgEmpMapper;
import com.zhitong.money.services.api.IMsgEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Andy Zhang
 * @Description:
 * @Date: 11:11 2021/3/5
 * @Company: wisecard
 */
@Service
public class MsgEmpService implements IMsgEmpService {

    @Autowired
    private MsgEmpMapper msgEmpMapper;

    @Override
    public List<MsgEmp> findMsgEmpByMid(String mid) throws Exception {
        List<MsgEmp> relatedByMid = msgEmpMapper.findRelatedByMid(mid);
        return relatedByMid;
    }

    @Override
    public List<MsgEmp> findMsgEmpByTid(String tid) throws Exception {
        List<MsgEmp> relatedByTid = msgEmpMapper.findRelatedByTid(tid);
        return relatedByTid;
    }

    @Override
    public void updateStatus(MsgEmp msgEmp) throws Exception {
        try {
            msgEmpMapper.updateRelatedStatus(msgEmp.getMid(),msgEmp.getTid(),msgEmp.getStatus());
        } catch (Exception e) {
            throw new UpdateException("updateStatus:更新失败"+e.getMessage());
        }

    }

    @Override
    public void updateEnable(MsgEmp msgEmp) throws Exception {
        try {
            msgEmpMapper.updateEnable(msgEmp.getMid(),msgEmp.getTid(),msgEmp.getEnable());
        } catch (Exception e) {
            throw new UpdateException("updateEnable:更新失败"+e.getMessage());
        }
    }
}
